package com.xzc.refactory.method.splitTemporaryVariable;

public class C4 {
    double _primaryForce;
    double _secondaryForce;
    double _mass;
    int _delay;

    double getDistanceTravelled(int time) {
        double result;
        //first acc
        int primaryTime = Math.min(time, _delay);
        result = 0.5 * getPrimaryAcc() * primaryTime * primaryTime;
        int secondaryTime = time - _delay;
        if (secondaryTime > 0) {
            double primaryVel = getPrimaryAcc() * _delay;
            //sec acc
            final double secondaryAcc = (_primaryForce + _secondaryForce) / _mass;
            result += primaryVel * secondaryTime + 0.5 * secondaryAcc * secondaryTime * secondaryTime;
        }
        return result;
    }

    double getPrimaryAcc() {
        return _primaryForce / _mass;
    }
}
